package view;

import java.awt.GraphicsEnvironment;
import java.util.ArrayList;

import eventHandling.Callback;
import eventHandling.EventBus;
import eventHandling.EventTyp.Type;

/**
 * CheckerDialogController is the Controller for the CheckerDialog and manages
 * all user inputs and updates the view if needed.
 * 
 * @author sloth42
 * 
 */
public class CheckerDialogController implements Controller {

	private EventBus eventBus;
	private CheckerDialog checkerDialog;
	private ArrayList<Controller> subController = new ArrayList<Controller>();

	public CheckerDialogController(EventBus eventBus,
			CheckerDialog checkerDialog) {
		this.eventBus = eventBus;
		this.checkerDialog = checkerDialog;

		registerForEvents();
	}

	private void registerForEvents() {
		eventBus.register(Type.LEARN_UNLEARNED_CARDS, new Callback() {

			public void actionPerformed() {
				checkerDialog.setVisible(true);
			}
		});

		eventBus.register(Type.FULLSCREEN_MODE_CHECKER_DIALOG, new Callback() {

			public void actionPerformed() {
				checkerDialog.setVisible(false);
				checkerDialog.dispose();
				checkerDialog.setResizable(false);
				if (!checkerDialog.isDisplayable()) {
					checkerDialog.setUndecorated(true);
				}

				GraphicsEnvironment ge = GraphicsEnvironment
						.getLocalGraphicsEnvironment();
				ge.getDefaultScreenDevice().setFullScreenWindow(checkerDialog);
				checkerDialog.setVisible(true);

			}
		});
	}
	
	public void addSubcontroller(Controller subController) {
		this.subController.add(subController);
	}

}
